package com.insmess.speech.controller;

import com.insmess.speech.common.api.CommonResult;
import com.insmess.speech.dto.AsrDto;
import com.insmess.speech.sdk.dto.AsrResponseDto;
import com.insmess.speech.sdk.template.InsmessAsrTemplate;
import com.insmess.speech.service.AsrService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/asr")
public class AsrController {
    @Autowired
    private InsmessAsrTemplate insmessAsrTemplate;

    @Autowired
    private AsrService asrService;

    @PostMapping("/base64")
    public CommonResult base64(@RequestBody AsrDto asrDto) {
        try {
            return CommonResult.success("该功能尚未开发");
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @PostMapping("/file")
    public CommonResult file(MultipartFile file, AsrDto asrDto) {
        try {
            String content = asrService.asr(file);
            return CommonResult.success(content);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(e.getMessage());
        }
    }
}
